package com.jin.webvideo.entity;

import com.alibaba.fastjson.JSONObject;

public class ResultEntity {
    public static final int CODE_SECCESS = 0;
    public static final int CODE_FAIL = 1;
    private String msg;
    private int code;
    private Object data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    public static ResultEntity success(String msg, Object data){
        return newResultMsg(CODE_SECCESS, msg, data);
    }
    public static ResultEntity success(Object data){
        return success("sucess", data);
    }
    public static ResultEntity success(String msg){
        return success(msg, null);
    }
    public static ResultEntity success(){
        return newResultMsg(CODE_SECCESS, "", null);
    }
    public static ResultEntity fail(String msg, Object data){
        return newResultMsg(CODE_FAIL, msg, data);
    }
    public static ResultEntity fail(){
        return newResultMsg(CODE_FAIL, "", null);
    }
    public static ResultEntity fail(Object data){
        return newResultMsg(CODE_FAIL, "error", data);
    }
    public static ResultEntity fail(String msg){
        return newResultMsg(CODE_FAIL, msg, null);
    }
    private static ResultEntity newResultMsg(int code, String msg, Object data){
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setMsg(msg);
        resultEntity.setData(data);
        resultEntity.setCode(code);
        return resultEntity;
    }

    public String toJson(){
        return JSONObject.toJSONString(this);
    }
}
